<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <!-- hexo-inject:begin --><!-- hexo-inject:end --><meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.1">
  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/blog/images/logo.svg" color="#222">

<link rel="stylesheet" href="/blog/css/main.css">


<link rel="stylesheet" href="/blog/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"dw_zhouyu.gitee.io","root":"/blog/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
  </script>

  <meta name="description" content="牛客多校，写文章晚了，就不多废话了 由于我比较菜，就只记录下我参与的题目">
<meta property="og:type" content="article">
<meta property="og:title" content="2020 Nowcoder Summer Training 1">
<meta property="og:url" content="https://dw_zhouyu.gitee.io/blog/2020/07/19/2020%20Nowcoder%20Summer%20Training%201/index.html">
<meta property="og:site_name" content="DW_Zhouyu">
<meta property="og:description" content="牛客多校，写文章晚了，就不多废话了 由于我比较菜，就只记录下我参与的题目">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2020-07-19T11:36:50.000Z">
<meta property="article:modified_time" content="2021-01-04T12:03:28.308Z">
<meta property="article:author" content="DW_Zhouyu">
<meta property="article:tag" content="Nowcoder Training">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="https://dw_zhouyu.gitee.io/blog/2020/07/19/2020%20Nowcoder%20Summer%20Training%201/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>2020 Nowcoder Summer Training 1 | DW_Zhouyu</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript><!-- hexo-inject:begin --><!-- hexo-inject:end -->

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <!-- hexo-inject:begin --><!-- hexo-inject:end --><div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/blog/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">DW_Zhouyu</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">从你所在的方向 到我将踏足的战场 遥遥相隔</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/blog/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/blog/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/blog/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/blog/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/blog/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://dw_zhouyu.gitee.io/blog/2020/07/19/2020%20Nowcoder%20Summer%20Training%201/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/blog/images/avatar.gif">
      <meta itemprop="name" content="DW_Zhouyu">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="DW_Zhouyu">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          2020 Nowcoder Summer Training 1
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-07-19 19:36:50" itemprop="dateCreated datePublished" datetime="2020-07-19T19:36:50+08:00">2020-07-19</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2021-01-04 20:03:28" itemprop="dateModified" datetime="2021-01-04T20:03:28+08:00">2021-01-04</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/Training/" itemprop="url" rel="index"><span itemprop="name">Training</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <blockquote>
<p>牛客多校，写文章晚了，就不多废话了 由于我比较菜，就只记录下我参与的题目 <a id="more"></a></p>
</blockquote>
<h1 id="b-b-suffix-array">B B-Suffix Array</h1>
<h2 id="题意">题意</h2>
<p>设 <span class="math inline">\(mindiv(n)\)</span> 表示 <span class="math inline">\(n\)</span> 最小的非 <span class="math inline">\(1\)</span> 约数，有一棵树，<span class="math inline">\(1\)</span>号点为根，<span class="math inline">\(i\)</span> 号点向 <span class="math inline">\(\frac{i}{mindiv(i)}\)</span> 连边。设 <span class="math inline">\(f(u,v)\)</span> 表示在树上 <span class="math inline">\(u,v\)</span> 之间的路径长度。</p>
<p>给出 <span class="math inline">\(m\ (1\le m\le 10^5)\)</span> 个权值 <span class="math inline">\(w_i\)</span>。求一个点 <span class="math inline">\(u\)</span> 使得 <span class="math inline">\(\sum_{i=1}^{n} w_i*f(u,i!)\)</span>最小。</p>
<h2 id="题解">题解</h2>
<p>一个个人的思路，但是还没有通过...</p>
<p>首先我们把答案放在根节点，如果它不是最优的，那么一定是因为它有一颗子树，子树上 <span class="math inline">\(\sum wi\)</span> 大于总权值和的一半，那么我们此时把答案移动到这颗子树的根上，不断进行这个操作，直到不能移动。</p>
<p>不难分析，每个数都是从自己最大的质因数到最小的质因数一路下来的。</p>
<p>比如 <span class="math inline">\(60 = 1 * 5 * 3 * 2 * 2\)</span>，所以在树上从上到下就是 <span class="math inline">\(1\rightarrow 5 \rightarrow 15\rightarrow 30\rightarrow 60\)</span> 。</p>
<p>那么对于这些阶乘来说，它们的第一步都是它的最大的质因数，其实共享一个最大质因数的阶乘不多，数量就是相邻两个质数的间隔，这大约是<span class="math inline">\(log\)</span>级别的。所以我们按照我们提出的方法来优化答案，每次至少能剪掉一颗子树，复杂度是能够接受的。</p>
<p>总复杂度：<span class="math inline">\(O(n*log(n))\)</span></p>
<h1 id="h-minimum-cost-flow">H Minimum-cost Flow</h1>
<h2 id="题意-1">题意</h2>
<p>给出一个 <span class="math inline">\(n\)</span> 个点，<span class="math inline">\(m\)</span> 条边的网络 <span class="math inline">\((n\le 50,\ m\le 100)\)</span>，给出每条边的费用 <span class="math inline">\(c_i\)</span> 。</p>
<p>有 <span class="math inline">\(q\ (q\le10^5)\)</span> 次询问，每次询问一对 <span class="math inline">\(u, v\)</span>：求当每条边的流量均为<span class="math inline">\(\frac{u}{v}\)</span>的时候，一个流量为 <span class="math inline">\(1\)</span> 的可行流的最小费用是多少，无可行流输出 <span class="math inline">\(NaN\)</span>。</p>
<h2 id="题解-1">题解</h2>
<p>显然地题面上这是个费用流的问题，我们分析一下增广路算法，我们不停增广直到当前流量跑到 <span class="math inline">\(1\)</span> 就停下来即可。</p>
<p>注意到题目中，每条边的流量都是一样的，那么在增广路算法中，不论<span class="math inline">\(u,\ v\)</span>如何设置，每次增广的路径都是一样的。</p>
<p>不妨我们先把流量设为 <span class="math inline">\(1\)</span> ，先跑个费用流，记录下每次增广路的费用。</p>
<p>给出<span class="math inline">\(u, v\)</span>后，我们立即能算出需要多少条增广路，那么按照增广顺序从前往后选就行了，这里用个前缀和优化一下。</p>
<p>总复杂度：<span class="math inline">\(O(n^3)\)</span></p>

    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/blog/tags/Nowcoder-Training/" rel="tag"># Nowcoder Training</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/blog/2020/07/02/Untitled-1/" rel="prev" title="Codeforces Global Round 9">
      <i class="fa fa-chevron-left"></i> Codeforces Global Round 9
    </a></div>
      <div class="post-nav-item">
    <a href="/blog/2020/07/26/2020-Multi-University-Training-Contest-1/" rel="next" title="2020 Multi-University Training Contest 1">
      2020 Multi-University Training Contest 1 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#b-b-suffix-array"><span class="nav-number">1.</span> <span class="nav-text">B B-Suffix Array</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#题意"><span class="nav-number">1.1.</span> <span class="nav-text">题意</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#题解"><span class="nav-number">1.2.</span> <span class="nav-text">题解</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#h-minimum-cost-flow"><span class="nav-number">2.</span> <span class="nav-text">H Minimum-cost Flow</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#题意-1"><span class="nav-number">2.1.</span> <span class="nav-text">题意</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#题解-1"><span class="nav-number">2.2.</span> <span class="nav-text">题解</span></a></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">DW_Zhouyu</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/blog/archives/">
        
          <span class="site-state-item-count">12</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/blog/categories/">
          
        <span class="site-state-item-count">4</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/blog/tags/">
          
        <span class="site-state-item-count">6</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">DW_Zhouyu</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/blog/lib/anime.min.js"></script>
  <script src="/blog/lib/pjax/pjax.min.js"></script>
  <script src="/blog/lib/velocity/velocity.min.js"></script>
  <script src="/blog/lib/velocity/velocity.ui.min.js"></script>

<script src="/blog/js/utils.js"></script>

<script src="/blog/js/motion.js"></script>


<script src="/blog/js/schemes/pisces.js"></script>


<script src="/blog/js/next-boot.js"></script>

  <script>
var pjax = new Pjax({
  selectors: [
    'head title',
    '#page-configurations',
    '.content-wrap',
    '.post-toc-wrap',
    '.languages',
    '#pjax'
  ],
  switches: {
    '.post-toc-wrap': Pjax.switches.innerHTML
  },
  analytics: false,
  cacheBust: false,
  scrollTo : !CONFIG.bookmark.enable
});

window.addEventListener('pjax:success', () => {
  document.querySelectorAll('script[data-pjax], script#page-configurations, #pjax script').forEach(element => {
    var code = element.text || element.textContent || element.innerHTML || '';
    var parent = element.parentNode;
    parent.removeChild(element);
    var script = document.createElement('script');
    if (element.id) {
      script.id = element.id;
    }
    if (element.className) {
      script.className = element.className;
    }
    if (element.type) {
      script.type = element.type;
    }
    if (element.src) {
      script.src = element.src;
      // Force synchronous loading of peripheral JS.
      script.async = false;
    }
    if (element.dataset.pjax !== undefined) {
      script.dataset.pjax = '';
    }
    if (code !== '') {
      script.appendChild(document.createTextNode(code));
    }
    parent.appendChild(script);
  });
  NexT.boot.refresh();
  // Define Motion Sequence & Bootstrap Motion.
  if (CONFIG.motion.enable) {
    NexT.motion.integrator
      .init()
      .add(NexT.motion.middleWares.subMenu)
      .add(NexT.motion.middleWares.postList)
      .bootstrap();
  }
  NexT.utils.updateSidebarPosition();
});
</script>




  















    <div id="pjax">
  

  
      

<script>
  if (typeof MathJax === 'undefined') {
    window.MathJax = {
      loader: {
        source: {
          '[tex]/amsCd': '[tex]/amscd',
          '[tex]/AMScd': '[tex]/amscd'
        }
      },
      tex: {
        inlineMath: {'[+]': [['$', '$']]},
        tags: 'ams'
      },
      options: {
        renderActions: {
          findScript: [10, doc => {
            document.querySelectorAll('script[type^="math/tex"]').forEach(node => {
              const display = !!node.type.match(/; *mode=display/);
              const math = new doc.options.MathItem(node.textContent, doc.inputJax[0], display);
              const text = document.createTextNode('');
              node.parentNode.replaceChild(text, node);
              math.start = {node: text, delim: '', n: 0};
              math.end = {node: text, delim: '', n: 0};
              doc.math.push(math);
            });
          }, '', false],
          insertedScript: [200, () => {
            document.querySelectorAll('mjx-container').forEach(node => {
              let target = node.parentNode;
              if (target.nodeName.toLowerCase() === 'li') {
                target.parentNode.classList.add('has-jax');
              }
            });
          }, '', false]
        }
      }
    };
    (function () {
      var script = document.createElement('script');
      script.src = '//cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js';
      script.defer = true;
      document.head.appendChild(script);
    })();
  } else {
    MathJax.startup.document.state(0);
    MathJax.texReset();
    MathJax.typeset();
  }
</script>

    

  

    </div><!-- hexo-inject:begin --><!-- hexo-inject:end -->
</body>
</html>
